package com.itheima.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;

import javax.sql.DataSource;
import javax.xml.crypto.Data;

public class JdbcConfig {
    @Value("${jdbc.driver}")
    private String driverClassName;
    @Value("${jdbc.url}")
    private String url;
    @Value("${jdbc.username}")
    private String username;
    @Value("${jdbc.password}")
    private String password;
     @Bean("dataSource")
    public DataSource getDataSource(){
        //1 创建连接池对象
        DruidDataSource dataSource = new DruidDataSource();
        //2 设置连接参数
   dataSource.setDriverClassName(driverClassName);
   dataSource.setUrl(url);
   dataSource.setUsername(username);
   dataSource.setPassword(password);
        //3 返回连接池对象
         return dataSource;
    }
}
